package com.order.api.controller;

import com.order.api.po.TblMenu;
import com.order.api.service.TblMenuService;
import com.order.api.target.Authorization;
import com.order.api.target.MethodLog;
import com.order.api.vo.BaseResult;
import com.order.api.vo.request.MenuIdRequest;
import com.order.api.vo.request.MenuSaveRequest;
import com.order.api.vo.request.MenuStateRequest;
import com.order.api.vo.response.MenuListResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "菜单模块")
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private TblMenuService tblMenuService;

    @ApiOperation("菜单保存")
    @Authorization
    @RequestMapping(value = "save",method = RequestMethod.POST)
    @MethodLog(optType = "菜单保存",systemModel = "菜单模块")
    public BaseResult<String> saveMenu(@RequestBody MenuSaveRequest request){
        return BaseResult.judgeOperate(tblMenuService.saveMenu(request));
    }

    @ApiOperation("菜单详情")
    @Authorization
    @RequestMapping(value = "detail",method = RequestMethod.POST)
    @MethodLog(optType = "菜单详情",systemModel = "菜单模块")
    public BaseResult<TblMenu> menuDetail(@RequestBody MenuIdRequest request){
        return BaseResult.success(tblMenuService.detailMenu(request));
    }

    @ApiOperation("菜单删除")
    @Authorization
    @RequestMapping(value = "delete",method = RequestMethod.POST)
    @MethodLog(optType = "菜单删除",systemModel = "菜单模块")
    public BaseResult<String> deleteMenu(@RequestBody MenuIdRequest request){
        return BaseResult.judgeOperate(tblMenuService.deleteMenu(request));
    }

    @ApiOperation("菜单列表")
    @Authorization
    @RequestMapping(value = "list",method = RequestMethod.POST)
    @MethodLog(optType = "菜单列表",systemModel = "菜单模块")
    public BaseResult<List<MenuListResponse>> listMenu(){
        return BaseResult.success(tblMenuService.findList());
    }

    @ApiOperation("更新状态")
    @Authorization
    @RequestMapping(value = "updateState",method = RequestMethod.POST)
    @MethodLog(optType = "更新状态",systemModel = "菜单模块")
    public BaseResult<String> updateState(MenuStateRequest request){
        return BaseResult.judgeOperate(tblMenuService.updateState(request));
    }
}
